#include "MCIncidentConstraintVisual.h"
#include <MCIncidentConstraint.h>
#include <iostream>
#include <MCSettings.h>

MCIncidentConstraintVisual::MCIncidentConstraintVisual(ICanvas *presenter, MCIncidentContraint *constraint) :
    MCConstraintVisual(presenter, constraint),
    _grip(constraint->_grip1),
    _offset(MCSettings::constraintLabelOffset)
{
}

void MCIncidentConstraintVisual::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    setPainter(painter);

    double size = MCSettings::LabelSize;
    drawLabel(transformed(), size, size, "resources/incident.png");
}

QPainterPath MCIncidentConstraintVisual::shape() const
{
    QPainterPath path;
    double size = MCSettings::LabelSize;
    QPointF center(transformed().x, transformed().y);
    QPointF tl(center.x() - size, center.y() + size);
    QPointF br(center.x() + size, center.y() - size);

    path.addRect(QRectF(tl, br));

    return path;
}

MCPoint2D MCIncidentConstraintVisual::transformed() const
{
    return presenter->screenToWorld(_grip->position() + labelOffset);
}
